﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using STLGROUP.Layers.Presentations.FormBase;
using STLGROUP.Layers.Common;
using STLGROUP.Layers.DataAccessLayers;

namespace QuanLyBanHang
{
    /// <summary>
    /// PF003 - Cap nhap trang thai nhan vien
    /// </summary>
    /// <author>viet sang</author>
    /// <date>16/06/2012</date>
    public partial class PF003 : frmBase
    {
        private DT_NhanVien _nhanVien;

        public DT_NhanVien NhanVien
        {
            get { return _nhanVien; }
            set { _nhanVien = value; }
        }
        private QuanLyBanHangEntities _context;

        public PF003()
        {
            InitializeComponent();
            this.Load += new EventHandler(PF003_Load);
        }

        private void PF003_Load(object sender, EventArgs e)
        {
            cboTrangThai.DataSource = _context.DM_TrangThaiNhanVien;
            cboTrangThai.DisplayMember = "TenTrangThaiNhanVien";
            cboTrangThai.ValueMember = "IDTrangThaiNhanVien";

            if (NhanVien != null)
            {
                cboTrangThai.SelectedValue = NhanVien.IDTrangThaiNhanVien ?? -1;
                txtTenSanPham.Text = NhanVien.TenDayDu;
                txtGhiChu.Text = NhanVien.GhiChu;
            }
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            try
            {
                if (NhanVien != null && cboTrangThai.SelectedValue != null)
                {
                    int idTrangThai;
                    if (int.TryParse(cboTrangThai.SelectedValue.ToString(), out idTrangThai))
                    {
                        if (idTrangThai != -1)
                        {
                            NhanVien.IDTrangThaiNhanVien = idTrangThai;
                            NhanVien.GhiChu += txtGhiChu.Text;
                        }
                    }
                }

                if (_context.SaveChanges() > 0)
                {
                    UICommon.ShowMessegeInfo(Const.MSG_UPDATE_SUCESSFULL);
                    DialogResult = System.Windows.Forms.DialogResult.OK;
                }
                else
                {
                    UICommon.ShowMessegeInfo(Const.MSG_UPDATE_NOT_SUCESSFULL);
                    DialogResult = System.Windows.Forms.DialogResult.Cancel;
                }
            }
            catch { }
            
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public QuanLyBanHangEntities Context
        {
            get { return _context; }
            set { _context = value; }
        }
    }
}
